package com.zjc.app.api.sdk.client;

import com.google.gson.reflect.TypeToken;
import com.zjc.app.api.sdk.dto.ResultDto;
import com.zjc.app.api.sdk.dto.result.ApiDictionaryDTO;
import com.zjc.app.api.sdk.exception.AppBizRuntimeException;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class ConfigClient extends BaseClient {

    public ConfigClient(String serverUrl, String appId, String appSecret, Integer connectTimeout, Integer readTimeout) {
        super(serverUrl, appId, appSecret, connectTimeout, readTimeout);
    }

    /**
     * 查询字典
     * @param parentDicId 父字典ID
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<List<ApiDictionaryDTO>> getDictionaries(int parentDicId) throws IOException, AppBizRuntimeException {
        String url = "/v1/dict/list";
        Map<String, String> params = new TreeMap<>();
        params.put("parentDicId", String.valueOf(parentDicId));
        return super.doGet(url, params, new TypeToken<ResultDto<List<ApiDictionaryDTO>>>() {});
    }
}
